home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / srefv12i.zip / virtcfg.cmd < prev    next >
OS/2 REXX Batch file  |  1997-03-21  |  16KB  |  426 lines

  1. /*  */
  2. virtcfg:
  3.  
  4. CHECKIT=0   /* Change this to 0 if you want to enable REMOTE configuration by SUPERUSERS */
  5.  
  6. /* background color */
  7. USECOLOR='2dd52f'
  8.  
  9. /* ---------------- DO NOT MODIFY BELOW THIS LINE  ------------------ */
  10.  
  11. parse arg ddir,tempfile,sel,list,verb,uri,user,basedir,workdir,privset,enmadd,transaction,verbose
  12.  
  13. if verb="" then do
  14.    say " This SRE-Filter add-on is NOT meant to be run from the command line."
  15.    say " It can be invoked by using CONFIGUR.HTM "
  16.    exit
  17. end  /* Do */
  18.  
  19.  
  20. list=translate(list, ' ', '+'||'090a0d'x)  /* Whitespace, etc. */
  21.  
  22. who2=extract('CLIENTADDR')
  23. saddr2=extract('SERVERADDR')
  24.  
  25. select
  26.    when checkit=1 then do
  27.  
  28. /* only if user = serveraddress !!! */
  29.      if who2<>saddr2 then do
  30.  
  31.         call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  32.         call lineout tempfile, "<html><head><title>SREFILTER ERROR </title>"
  33.         call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  34.  
  35.         call lineout tempfile,' <strong> Action not allowed remotely.</strong> <pre>'
  36.         call lineout tempfile,' </body> </html> '
  37.         call lineout tempfile
  38.         'FILE ERASE TYPE text/html NAME' tempfile
  39.         return 'VIRTCFG: action not allowed remotely. '
  40.      end
  41.    end
  42.    otherwise do
  43.       if wordpos('SUPERUSER',privset)=0 then do
  44.         'RESPONSE HTTP/1.0 401 Unauthorized '     /* Set HTTP response line */
  45.         'header add WWW-Authenticate: Basic Realm=<CONFIGURE>'  /* challenge */
  46.  
  47.         call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  48.         call lineout tempfile, "<html><head><title>Not authorized </title>"
  49.         call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  50.  
  51.         call lineout tempfile,' <strong> You do not have configuration rights.</strong> <pre>'
  52.         if who2=saddr2 then 
  53.                 call lineout tempfile,'<br> <Em> You may want to edit VIRTCFG.CMD </em> '
  54.         call lineout tempfile,' </body> </html> '
  55.         call lineout tempfile
  56.          iia=dosdir(tempfile,'s')
  57.  
  58.         'FILE ERASE TYPE text/html NAME' tempfile
  59.         return '401 'iia ' VIRTCFG: not permitted to configure. '
  60.       end
  61.    end
  62. end
  63.  
  64. list=strip(list)
  65. select 
  66.    when upper(list)='TODO=SHOW' | upper(list)='TODO=SHOW_HEADER' then
  67.         signal doshow
  68.    when upper(list)='TODO=SET' then
  69.         signal doset
  70.    otherwise
  71.         signal dochange
  72. end  /* select */
  73.  
  74.  
  75. /* jump here to show values */
  76. doshow:
  77.  
  78. virtualfile=value(enmadd||'VIRTUAL_FILE',,'os2environment')
  79.    call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  80.    call lineout tempfile, "<html><head><title>SRE-Filter: Virtual Directories </title>"
  81.    call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  82.  
  83.  
  84. aa=fileread(virtualfile,'lins',,'E')
  85.  
  86. call lineout tempfile, "<h1> SRE-Filter:  Virtual Directories  </h1> <p>"
  87.  
  88. if upper(list)='TODO=SHOW' then
  89.    call lineout tempfile, "<h2> List of "header" comments </h2> <pre> <blockquote>"
  90. else
  91.    call lineout tempfile, "<h2> Description of virtual directories </h2> <pre> <blockquote>"
  92.  
  93. /* show "header comments" */
  94. iat=0
  95. do until iat >= lins.0
  96.    iat=iat+1
  97.    if  abbrev(strip(lins.iat),';')  then do
  98.         foo=strip(lins.iat) ;foo=strip(foo,'l',';')
  99.          call lineout tempfile, foo 
  100.    end  /* Do */
  101.    else do
  102.         leave
  103.    end
  104. end /* do -- iat is the first non header comment line  */
  105. call lineout tempfile, '</blockquote></pre> '
  106.  
  107. /* view descriptive header only? */
  108. if upper(list)='TODO=SHOW_HEADER' then do
  109.    call lineout tempfile,' <hr> </body></html>'
  110.    call lineout tempfile
  111.    'file erase  type text/html name  ' tempfile
  112.    return ' done '
  113. end  /* Do */
  114.  
  115.  
  116.  
  117. /* read in usernames, etc */
  118. nusers=0
  119.  
  120. call lineout tempfile, ' <hr> <h2> List of virtual directories </h2>  '
  121.  
  122. call lineout tempfile,' Notes: <ul> '
  123. call lineout tempfile,' <li> Virtual directories are stored in: ' virtualfile
  124. call lineout tempfile,' <li> <em>Comments are in italics </em> '
  125. call lineout tempfile, ' <li> Entries with no <strong>host nickname</strong> apply to all requests '
  126. call lineout tempfile, ' <li> Valid keywords for limitation list are: <b> !CGI-BIN !UPLOAD !ADDONS !HTML </B></ul> <br>'
  127.  
  128. call lineout tempfile,' <table border=1> <th> Host Nickname </th>'
  129. call lineout tempfile,' <th> Candidate SEL Fragment </th>'
  130. call lineout tempfile,'  <th> Fully qualified directory (or remote directory)  </th> '
  131. call lineout tempfile,' <th> Allow subdirectories <br> & <code> limitation list </code> </th><tr>'
  132.  
  133. do mm=iat to lins.0
  134.   if lins.mm=' ' then iterate
  135.   if  abbrev(strip(lins.mm),';') then do  
  136.        call lineout tempfile,'<td colspan=4>  <code>     </code> <em>' strip(strip(lins.mm),'l',';') '</em></td> <tr> '
  137.   end
  138.   else do
  139.       if pos('// ',lins.mm)>0 then
  140.            parse var lins.mm hostname '//' candurl targdir limlist
  141.       else do
  142.            hostname=' .. '
  143.            parse var lins.mm candurl targdir limlist
  144.       end  /* Do */
  145.       subdirok='NO'
  146.       if right(strip(targdir),1)='*' then do
  147.          targdir=delstr(targdir,length(targdir))
  148.          subdirok='YES'
  149.       end
  150.       call lineout tempfile,'<td> <STRONG> 'hostname '</STRONG> </td>'
  151.       call lineout tempfile,'<td> <STRONG> ' candurl '</STRONG> </td>'
  152.       call lineout tempfile,'<td> <STRONG> 'targdir '</STRONG> </td>'
  153.       call lineout tempfile,' <td> <strong> ' subdirok '</strong> <br> '
  154.       call lineout tempfile,'  <code> ' limlist '</code> </td> <tr> '
  155.  
  156.   end /* do */
  157.  
  158. end
  159. call lineout tempfile,' </table>'
  160.  
  161. call lineout tempfile,' <hr> Thanks for checking </body></html>'
  162. call lineout tempfile
  163.  
  164. foo=sref_expire_response(0.05,dosdir(tempfile))
  165. 'file erase  type text/html name  ' tempfile
  166. return ' done '
  167.  
  168.  
  169. /* jump here if "set values" chosen */
  170. doset:
  171. virtualfile=value(enmadd||'virtual_FILE',,'os2environment')
  172. aa=fileread(virtualfile,'lins',,'E')
  173.  
  174. call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  175. call lineout tempfile, "<html><head><title>SRE-Filter: modify virtual directorires </title>"
  176. call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  177.  
  178. /* ignore header stuff */
  179. iat=0
  180. do until iat >= lins.0
  181.    iat=iat+1
  182.    if  abbrev(strip(lins.iat),';') | lins.iat=' ' then iterate
  183.    leave
  184. end /* do -- iat is the first non header comment line  */
  185. call lineout tempfile, "<h1> SRE-Filter: modify <A NAME="top">virtual</A> directories </h1> <p>"
  186. call lineout tempfile,' <blockquote> You can modify, remove, or add virtual directories'
  187. call lineout tempfile,' <br><em> Questions? <A HREF="#notes">The notes might help.</A> </em> </blockquote> '
  188.  
  189. call lineout tempfile,' <h2> Modify or remove current virtual directories </h2>'
  190. call lineout tempfile,'<FORM ACTION="/virtcfg" METHOD="POST">'
  191.  
  192. call lineout tempfile,' <table border=1> <th> Host Nickname <br> (see below  for a <br>listing of <A href="#hosts">current hosts</A>)  </th>'
  193. call lineout tempfile,' <th> Candidate SEL Fragment <br> (set to blank to  delete the entry)</th>'
  194. call lineout tempfile,'  <th> Local or remote directory   </th> '
  195. call lineout tempfile,' <th> Allow subdirectories, <br> and optional limtation_list? </th><tr>'
  196.  
  197. nhidden=0 ; mm=0
  198. do mm0=iat to lins.0
  199.     alin=translate(lins.mm0,' ','1a000d0a'x)
  200.     mm=mm+1
  201.     if  abbrev(strip(alin),';')=1 | alin=' ' then do
  202.         nhidden=nhidden+1
  203.         hiddens.nhidden='<INPUT TYPE="HIDDEN" name="COMMENT.'||mm||'"  value="'||alin||'" >'
  204.         iterate
  205.     end
  206.  
  207. /* non comment */
  208.     if pos('// ',alin)>0 then
  209.              parse var alin hostname '//' candurl absdir limlist
  210.         else do
  211.              hostname='  '
  212.              parse var alin candurl absdir limlist
  213.      end  /* Do */
  214.      candurl=strip(candurl)
  215.      subdirok=0
  216.      if right(strip(absdir),1)='*' then do
  217.          absdir=delstr(absdir,length(absdir))
  218.          subdirok=1
  219.      end
  220.      call lineout tempfile,'<td> <EM>Host nickname:</EM> <br> <INPUT TYPE="text" NAME="hostname.'||mm||'"'
  221.      call lineout tempfile,'value="'hostname'" SIZE=8 MAXLENGTH=15> </td> '
  222.      call lineout tempfile,'<td> <EM>Candidate:</EM> <br> <INPUT TYPE="text" NAME="candurl.'||mm||'"'
  223.      call lineout tempfile,'value="'candurl'" SIZE=18 MAXLENGTH=55> </td> '
  224.      call lineout tempfile,'<td> <EM>Target:</EM> <br> <INPUT TYPE="text" NAME="absdir.'||mm||'"'
  225.      call lineout tempfile,'value="'absdir'" SIZE=18 MAXLENGTH=55> </td> '
  226.      call lineout tempfile,'  <td> <INPUT TYPE=CHECKBOX NAME="subdirok.'mm||'" '
  227.      if subdirok=1 then
  228.           call lineout tempfile,' CHECKED >Sub directories ok? <br> '
  229.      else
  230.          call lineout tempfile,' > Sub directories ok? <br> '
  231.      call lineout tempfile,' <br>'
  232.      call lineout tempfile,'<br> <EM>Limitation_list:</EM> <br> <INPUT TYPE="text" NAME="limlist.'||mm||'"'
  233.      call lineout tempfile,'value="'limlist'" SIZE=12 MAXLENGTH=35> </td> '
  234.  
  235.  
  236.      if mm0<lins.0 then do
  237.            call lineout tempfile,'<tr>' ; call lineout tempfile,' '
  238.      end
  239. end
  240. call lineout tempfilem,' '
  241.  
  242. /* --- allow user to enter a few new names */
  243. call lineout tempfile,' </table>  <p> <h2> Add virtual directories </h2> <table border=1>'
  244. mm0=mm
  245. do mm=mm0+1 to mm0+3
  246.      call lineout tempfile,'<td> <EM>Host nickname:</EM> <br> <INPUT TYPE="text" NAME="hostname.'||mm||'"'
  247.      call lineout tempfile,'value=" " SIZE=8 MAXLENGTH=15> </td> '
  248.      call lineout tempfile,'<td> <EM>Candidate SEL:</EM> <br> <INPUT TYPE="text" NAME="candurl.'||mm||'"'
  249.      call lineout tempfile,'value=" " SIZE=18 MAXLENGTH=55> </td> '
  250.      call lineout tempfile,'<td> <EM>Fully qualified directory:</EM> <br> <INPUT TYPE="text" NAME="absdir.'||mm||'"'
  251.      call lineout tempfile,'value=" " SIZE=18 MAXLENGTH=55> </td> '
  252.  
  253.      call lineout tempfile,'  <td> <INPUT TYPE=CHECKBOX NAME="subdirok.'mm||'"> Sub directories ok? '
  254.      call lineout tempfile,'<br> <EM>Optional limitation_list:</EM> <br> <INPUT TYPE="text" NAME="limlist.'||mm||'"'
  255.      call lineout tempfile,'value=" " SIZE=14 MAXLENGTH=35> </td> '
  256.  
  257.      if mm<mm0+3 then call lineout tempfile,' <tr> '
  258. end
  259.  
  260. call lineout tempfile,'</table> <p>'
  261.  
  262.  
  263. /* ----- add comments information */
  264.  
  265. do jj=1 to nhidden
  266.    call lineout tempfile,hiddens.jj
  267. end /* do */
  268. call lineout tempfile,' <input type="hidden" name="entries" value="'||mm||'">'
  269. call lineout tempfile,' <input type="submit"> <input type="reset"> </form> '
  270.  
  271.  
  272. call lineout tempfile,' <hr> <h3> <A NAME="notes">Notes </A></h3> <ul> <li> Virtual directories are stored in: 'virtualfile
  273. call lineout tempfile,' <li> If a  <em>candidate SEL</em> is an abbreviation for a <em>request selector</em>, '
  274. call lineout tempfile,' <br> the associated <em>fully qualified directory </em> is used.'
  275. call lineout tempfile,' <li> The <em>optional </em> limitation_list can contain any of the following: <b> !HTML !ADDONS  !CGI-BIN !UPLOAD </b>'
  276. call lineout tempfile,' <li> To specify a "remote" directory (on another server), use a fully specified (http://...) URL '
  277. call lineout tempfile,' as the <em>fully qualified directory </em> '
  278. call lineout tempfile,' <li> Do you want to view a  more complete description of '
  279. call lineout tempfile,' <a href="/virtcfg?TODO=SHOW_HEADER"> virtual directories </a>?'
  280. call lineout tempfile,' <li> To add more then 3 new virtual directories, just rerun this several times, <br> or edit ' virtualfile
  281. call lineout tempfile,' <li> <em>Comments are NOT displayed </em>  <li> Case is ignored '
  282. call lineout tempfile,' <li> Selecting <em>subdirectories ok </em> permits access to the subtree under the <em>fully qualified directory </em>'
  283. call lineout tempfile, ' <li> Entries with no <strong>host nickname</strong> will apply to all requests</ul> <br>'
  284.  
  285. call lineout tempfile,' <h3> A list of the <A NAME="hosts">current hosts</A> </h3>  <blockquote> '
  286.  
  287. ii=value(enmadd||'HOSTS.0',,'os2environment')
  288. if ii>0 then do
  289. call lineout tempfile,' <table> <th> IP address </th> <th> Host Nickname </th> <th> Data Directory </th> <tr> '
  290. do ll=1 to ii
  291.    wow=value(enmadd||'HOSTS.'||ll,,'os2environment')
  292.    parse var wow ip ',' hn ',' hdir
  293.    call lineout tempfile,' <td> ' ip  '</td> <td> ' hn ' </td> <td> ' hdir '</td> <tr> '
  294. end /* do */
  295. call lineout tempfile,' </table> </blockquote>'
  296. end
  297. else do
  298.   call lineout tempfile,' No HOSTS have been defined   </blockquote>'
  299. end
  300.  
  301. call lineout tempfile,' <p> <A HREF="#top">Return to the top of this form.</A>'
  302.  
  303. call lineout tempfile,'</body></html>'
  304. call lineout tempfile
  305.  
  306. foo=sref_expire_response(0.05,dosdir(tempfile))
  307.  
  308. 'file erase  type text/html name  ' tempfile
  309. return ' done '
  310.  
  311.  
  312.  
  313. /******************** jump here to recrod changes */
  314. dochange:
  315. parse upper var list foo 'ENTRIES=' nentries '&' .
  316. do ii1=1 to nentries
  317.    fillme.ii1.0=0
  318. end /* do */
  319.  
  320. do until list=""
  321.    parse var list aa '&' list
  322.    parse upper var aa avar '.' aind '=' aval
  323.    aval=packur(aval)
  324.    if abbrev(avar,'ENTRIES=')=1 then iterate
  325.    wow=fillme.aind.0+1
  326.    fillme.aind.0=wow
  327.    fillme.aind.wow.var=avar ; fillme.aind.wow.val=aval
  328.    select
  329.       when avar="COMMENT" then do
  330.           fillme.aind.type='COMMENT'
  331.           parse  var aa foo '=' aval
  332.           fillme.aind.wow.val=packur(aval)
  333.       end
  334.       when avar="CANDURL" then fillme.aind.type='URL'
  335.       otherwise nop
  336.    end
  337. end /* do */
  338.  
  339. virtualfile=value(enmadd||'virtual_FILE',,'os2environment')
  340. aa=fileread(virtualfile,'lins',,'E')
  341.  
  342. /* pull "header comments" */
  343. iat=0
  344. do until iat >= lins.0
  345.    iat=iat+1
  346.    if  abbrev(strip(lins.iat),';')  then do
  347.        newlines.iat=lins.iat
  348.    end  /* Do */
  349.    else do
  350.         leave
  351.    end
  352. end /* do -- iat is the first non header comment line  */
  353. iat=iat-1
  354.  
  355. do uu=1 to nentries
  356.    select
  357.       when fillme.uu.type='COMMENT' then do
  358.           iat=iat+1
  359.           newlines.iat=fillme.uu.1.val
  360.       end
  361.       when fillme.uu.type='URL' then do
  362.           candurl=' ' ; absdir=' ' ; hostname=' ';subdirok=' ';limlist=" "
  363.           do uu2=1 to fillme.uu.0
  364.              chk1=fillme.uu.uu2.var
  365.              vvv=fillme.uu.uu2.val
  366.              select
  367.                 when chk1='CANDURL' then candurl=vvv
  368.                 when chk1='ABSDIR' then absdir=vvv
  369.                 when chk1='HOSTNAME' then hostname=vvv
  370.                 when chk1="LIMLIST" then limlist=vvv
  371.                 when chk1='SUBDIROK' then subdirok='*'
  372.                 otherwise nop
  373.              end
  374.           end
  375.           if candurl<>' ' then do
  376.               iat=iat+1
  377.               newlines.iat=''
  378.               if hostname<>' ' then
  379.                   newlines.iat=hostname||'// '
  380.               if subdirok='*' then
  381.                   absdir=strip(absdir,'t','\')||'\'
  382.               newlines.iat=newlines.iat||candurl' ' absdir||subdirok||' '||limlist
  383.           end
  384.       end
  385.       otherwise do
  386.             nop
  387.       end  /* Do */
  388.  
  389.   end                   /* select over type */
  390. end                     /* do over entries */
  391.  
  392. /* save to virtualfile.. but rename access_file first */
  393. foo=lastpos('.',virtualfile)
  394. if foo=0 then
  395.    acf1=virtualfile||'.'
  396. else
  397.    acf1=left(virtualfile,foo)
  398. do hi=1 to 999
  399.    try1=acf1||hi
  400.    if stream(acf1||hi,'c','query exists')='' then leave
  401. end /* do */
  402. foo=dosrename(virtualfile,try1)
  403. newlines.0=iat
  404. foo=filewrite(virtualfile,newlines,'R')
  405.  
  406.  
  407. call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  408. call lineout tempfile, "<html><head><titLE> SRE-Filter: Changed the virtual directories</title>"
  409. call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  410.  
  411. call lineout tempfile,' <h2>The virtual directories have been changed </h2>'
  412. call lineout tempfile,' The list of virtual directories has been saved to: ' virtualfile
  413. call lineout tempfile,' <p> The old version of 'virtualfile' has been moved to ' try1
  414. call lineout tempfile,' </body> </html> '
  415. call lineout tempfile
  416.  
  417. foo=value('SREF_REDO',1,'os2environment')
  418.  
  419.  
  420. 'FILE ERASE TYPE text/html NAME' tempfile
  421. return 'done change '
  422.  
  423.  
  424.  
  425.  
  426.